package com.banyuan.servlet.author;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
*  处理退出
*
* */

@WebServlet("/author/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 既然已经退出了，那就要把Session清除掉
        req.getSession().invalidate(); // invalidate() 清除Session
        System.out.println("Session 销毁完毕");
        // 重定向去 路径为index.jsp的Servlt，因为没登陆，过滤去会让页面跳转到登陆页面
        resp.sendRedirect(req.getContextPath());

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
